package com.cskaoyan.config.shiro;

import org.apache.shiro.session.InvalidSessionException;
import org.apache.shiro.session.mgt.SessionKey;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

/**
 * @author wangdezhao
 * @date 2021/6/6
 * @description
 */
public class CustomSessionManager extends DefaultWebSessionManager {
    @Override
    protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
        HttpServletRequest req = (HttpServletRequest) request;
        String AdminSessionId = req.getHeader("X-cskaoyan-mall-Admin-Token");
        if (AdminSessionId != null && !"".equals(AdminSessionId)){
            return AdminSessionId;
        }
        String userSessionId = req.getHeader("X-Litemall-Token");
        if (userSessionId != null && !"".equals(userSessionId)){
            return userSessionId;
        }
        return super.getSessionId(request, response);
    }
}
